package com.chenfubing.ps.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chenfubing.ps.entity.Appointment;
import com.chenfubing.ps.entity.pojo.RequestPojo;
import com.chenfubing.ps.entity.result.JsonResult;
import com.chenfubing.ps.service.IAppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author chenfubing
 * @since 2020-05-05
 */
@RestController
@RequestMapping("/appointment")
public class AppointmentController {

    @Autowired
    private IAppointmentService iAppointmentService;


    /**
     * 添加预约
     *
     * @param appointment
     */
    @PostMapping("/addAppointment")
    public JsonResult addAppointment(@Validated @RequestBody Appointment appointment) {
        iAppointmentService.addAppointment(appointment);
        return new JsonResult();
    }

    /**
     * 删除预约
     *
     * @param id
     */
    @GetMapping("/deleteAppointment")
    public JsonResult deleteAppointment(@RequestParam int id) {
        iAppointmentService.deleteAppointment(id);
        return new JsonResult();
    }

    /**
     * 获取分页
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/getAppointmentPage")
    public JsonResult getAppointmentPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize) {
        return new JsonResult(iAppointmentService.getAppointmentPage(pageNum, pageSize));
    }

    /**
     * 查询预约
     *
     * @param requestPojo
     * @return
     */
    @PostMapping("/getAppointmentList")
    public JsonResult getAppointmentList(@RequestBody RequestPojo requestPojo) {
        return new JsonResult(iAppointmentService.getAppointmentList(requestPojo.getStartTime(), requestPojo.getEndTime(), requestPojo.getLicense()));
    }
}
